﻿using System.Windows;
using System.Windows.Forms;
using UserControl = System.Windows.Controls.UserControl;

namespace GifToWebM.Panels
{
    /// <summary>
    /// Interaction logic for LocalizationChooserPanel.xaml
    /// </summary>
    public partial class LocalizationChooserPanel : UserControl
    {
        public delegate void PathChange();

        public event PathChange PathChangedEvent;

        public LocalizationChooserPanel()
        {
            InitializeComponent();
            
        }

        private void btnChoose_Click(object sender, RoutedEventArgs e)
        {
            FolderBrowserDialog fbDialog = new FolderBrowserDialog
            {
                ShowNewFolderButton = true,
                SelectedPath = txtPath.Text
            };

            var dialogResult = fbDialog.ShowDialog();
            if (dialogResult == DialogResult.OK)
            {
                Path = fbDialog.SelectedPath;
            }
        }

        public string Path
        {
            get
            {
                string tmp = "";
                Dispatcher.Invoke(() => { tmp = txtPath.Text; });
                return tmp;
            }
            set
            {
                txtPath.Text = value;
            }
        }

        public bool IsReadOnly
        {
            get { return txtPath.IsReadOnly; }
            set { txtPath.IsReadOnly = value; }
        }

        public string Header
        {
            get { return this.groupMain.Header as string; } 
            set { this.groupMain.Header = value; }
        }

        public bool DissableButton
        {
            get { return !btnChoose.IsEnabled; }
            set { btnChoose.IsEnabled = !value; }
        }

        private void txtPath_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
        {
            if (PathChangedEvent != null)
                PathChangedEvent();
        }
    }
}
